package com.midou.administration.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.midou.administration.bo.ClerkBo;
import com.midou.administration.bo.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.midou.administration.mapper.JournalMapper;
import com.midou.administration.entity.Journal;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.List;

@Service
public class JournalService{

    @Autowired
    private JournalMapper journalMapper;

    //查询登陆过这家店铺员工
   public Page queryJouranl(ClerkBo clerkBo){
       List<Journal> journalList=journalMapper.queryJouranl(clerkBo.getJournalPage(),clerkBo.getBusinessId());
       clerkBo.getJournalPage().setRecords(journalList);
       return clerkBo.getJournalPage();
   }
   //记录登录人员的信息
    public String saveRiZhi(Journal journal){
        InetAddress inetAddress= null;
        try {
            inetAddress = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        String ip=inetAddress.getHostAddress();//获得本机Ip
       journal.setIp(ip);
       journal.setLogintime(new Date());
       journal.setLoginSide("网页端");
       journalMapper.insert(journal);
       return null;
    }
    //删除登录日志
    public CommonResult deleteShop(Integer id){
       Integer num =journalMapper.deleteById(id);
       if(num>0){
           return new CommonResult(200,"删除成功");
       }else {
           return new CommonResult(500,"删除失败");
       }
    }


}
